from sqlalchemy import Column, Integer, String, DateTime, Boolean
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime
from db.DBUtil import DBUtil

Base = declarative_base()


class User(Base):
    __tablename__ = "sys_user"

    id = Column(Integer, primary_key=True)
    username = Column(String(80))
    nick_name = Column(String(80))
    password = Column(String(255))
    sex_type = Column(Integer)
    avatar = Column(String(255))
    introduction = Column(String(255))
    create_time = Column(DateTime, default=datetime.now)
    update_time = Column(DateTime, onupdate=datetime.now, default=datetime.now)


class Content(Base):
    __tablename__ = "t_content"
    id = Column(Integer, primary_key=True)
    title = Column(String(80))
    author = Column(String(80))
    content = Column(String(5000))
    category_code = Column(String(80))
    create_time = Column(DateTime, default=datetime.now)
    update_time = Column(DateTime, onupdate=datetime.now, default=datetime.now)


class ArticleCategory(Base):
    __tablename__ = "t_article_category"
    id = Column(Integer, primary_key=True)
    code = Column(String(80))
    name = Column(String(255))
    del_flag = Column(Boolean)
    create_time = Column(DateTime, default=datetime.now)
    update_time = Column(DateTime, onupdate=datetime.now, default=datetime.now)

# dbUtil = DBUtil()
# session = dbUtil.get_session()
# Base.metadata.create_all(dbUtil.get_engine())
# user1 = User(username='Willson2', nickname='墨爱', password='123456', age=32, gender=0)
# session.add(user1)
# session.commit()
